package com.example.demo.entity.security;

import com.alibaba.fastjson.JSON;
import com.example.demo.entity.Result;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.web.access.AccessDeniedHandler;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @description: 权限不足
 * @author: cj
 * @create: 09-02-10 09:25:04
 */
@Component
public class RoleAccessDeniedHandler implements AccessDeniedHandler {
    @Override
    public void handle(HttpServletRequest request, HttpServletResponse response,
                       AccessDeniedException accessDeniedException) throws IOException, ServletException {
        Result result = new Result();

        result.setStatus( 0002 );
        result.setMessage( "权限不足" );
        response.setCharacterEncoding( "UTF-8" );
        response.getWriter().write( JSON.toJSONString( result ) );
    }
}
